package com.corgi.encrypt.util;

import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * @title: Base64Util
 * @description:
 * @author: dengmiao
 * @create: 2019-10-23 14:04
 **/
public class Base64Util {

    /**
     * Decoding to binary
     * @param base64 base64
     * @return byte
     * @throws Exception Exception
     */
    public static byte[] decode(String base64) throws Exception {
        BASE64Decoder decoder = new BASE64Decoder();
        return decoder.decodeBuffer(base64);
        /*return Base64.decodeBase64(base64);*/
    }

    /**
     * Binary encoding as a string
     * @param bytes byte
     * @return String
     * @throws Exception Exception
     */
    public static String encode(byte[] bytes) throws Exception {
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(bytes);
        /*return new String(Base64.encodeBase64(bytes));*/
    }
}
